package hashtable;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-06-04 14:41
 * @ Description :
 */
public class HashTable
{
    private EmpLinkedList[] empLinkedList;
    private int size;

    public HashTable(int size)
    {
        this.size = size;
        empLinkedList = new EmpLinkedList[size];
        for (int i = 0; i < size; i++)
        {
            empLinkedList[i] = new EmpLinkedList();
        }
    }

    public void add(Emp emp)
    {
        empLinkedList[hash(emp.id)].add(emp);
    }

    public void list()
    {
        for (int i = 0; i < size; i++)
        {
            empLinkedList[i].list(i);
        }
    }

    public void findEmpById(int id)
    {
        Emp empById = empLinkedList[hash(id)].findEmpById(id);
        if (empById != null)
        {
            System.out.println("第" + (hash(id) + 1) +"条链表中找到员工");
        }
        else
        {
            System.out.println("没有找到该员工");
        }
    }

    public int hash(int id)
    {
        return id % size;
    }



}
